package com.syher.springboot.wechat.dispatcher;

import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.syher.springboot.wechat.common.Constant;
import com.syher.springboot.wechat.common.util.SmartChatUtil;
import com.syher.springboot.wechat.common.util.WeChatUtil;
import com.syher.springboot.wechat.message.MessageType;
import com.syher.springboot.wechat.message.response.NewsMessage;
import com.syher.springboot.wechat.message.response.TextMessage;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author shenyuhang
 * @date 2018/07/19.
 **/
public class MessageDispatcher {

    public static String process(Map<String, String> map) {
        String from = Preconditions.checkNotNull(map.get(Constant.WECHAT_FROM_USER_NAME));
        String to = Preconditions.checkNotNull(map.get(Constant.WECHAT_TO_USER_NAME));
        Preconditions.checkArgument(map.containsKey(Constant.WECHAT_MSG_TYPE) && !Strings.isNullOrEmpty(map.get(Constant.WECHAT_MSG_TYPE)));

        String msgType = map.get(Constant.WECHAT_MSG_TYPE);
        if (MessageType.Request.text.name().equals(msgType)) {
            TextMessage message = new TextMessage(to, from, SmartChatUtil.getReply(msgType));
            return WeChatUtil.MessageTool.messageToXml(message);
        }

        if (MessageType.Request.image.name().equals(msgType)) {
            return WeChatUtil.MessageTool.messageToXml(new TextMessage(to, from , "图片消息"));
        }

        if (MessageType.Request.link.name().equals(msgType)) {
        }

        if (MessageType.Request.location.name().equals(msgType)) {
            return WeChatUtil.MessageTool.messageToXml(new TextMessage(to, from, "定位消息"));
        }

        if (MessageType.Request.vedio.name().equals(msgType)) {
            return WeChatUtil.MessageTool.messageToXml(new TextMessage(to, from, "视频消息"));
        }

        if (MessageType.Request.voice.name().equals(msgType)) {
            return WeChatUtil.MessageTool.messageToXml(new TextMessage(to, from, "语音消息"));
        }

        if (MessageType.Request.shortvedio.name().equals(msgType)) {
            return WeChatUtil.MessageTool.messageToXml(new TextMessage(to, from, "短视频消息"));
        }

        return null;
    }

}
